//
//  WrapViewController.swift
//  Test
//
//  Created by rui on 2018/5/29.
//  Copyright © 2018年 qewqw. All rights reserved.
//

import UIKit

class WrapViewController: UIViewController {
    
    var contentViewController: UIViewController?

    private(set) var wrapNavigationController: WrapNavigationController?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        guard let vc = contentViewController else { return }

        let nav = WrapNavigationController()
        wrapNavigationController = nav
        wrapNavigationController?.wrapViewController = self
        
        nav.viewControllers = [vc]
        self.addChildViewController(nav)
        
        nav.view.frame = self.view.bounds
        nav.view.autoresizingMask = [.flexibleHeight,.flexibleWidth]
        self.view.addSubview(nav.view)
        
        nav.didMove(toParentViewController: self)
        

        // Do any additional setup after loading the view.
    }
}

///Navigation
var InteractivePopGestureKey = "RInteractivePopGesture"
var FullInteractivePopGesture = "RFullInteractivePopGesture"
var PopGestureRecognizerEnabledDistanceKey = "RPopGestureRecognizerEnabledDistance"
extension UIViewController {
    
    var isInteractivePopGestureRecognizerEnabled: Bool {
        set {
            objc_setAssociatedObject(self, InteractivePopGestureKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
        }
        get {
            return objc_getAssociatedObject(self, InteractivePopGestureKey) as? Bool ?? true
        }
    }
    
    var isFullInteractivePopGestureRecognizerEnabled: Bool {
        set {
            objc_setAssociatedObject(self, FullInteractivePopGesture, newValue, .OBJC_ASSOCIATION_ASSIGN)
        }
        get {
            return objc_getAssociatedObject(self, FullInteractivePopGesture) as? Bool ?? false
        }
    }
    
    var popGestureRecognizerEnabledDistance: CGFloat {
        set {
            objc_setAssociatedObject(self, PopGestureRecognizerEnabledDistanceKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
        }
        get {
            return objc_getAssociatedObject(self, PopGestureRecognizerEnabledDistanceKey) as? CGFloat ?? 0
        }
    }
    
    @objc func customBackItem() -> UIBarButtonItem? {
        return nil
    }
}


